


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
  <title>Coverage Report :: CoffeeMaker</title>
  <style type="text/css">
    @import "../../.css/coverage.css";
  </style>
</head>

<body>
<div class="header"></div>

<div class="content">
<div class="breadCrumbs">
    [ <a href="../../index.html">all classes</a> ]
    [ <a href="../index.html">edu.ncsu.csc326.coffeemaker</a> ]
</div>

<h1>Coverage Summary for Class: CoffeeMaker (edu.ncsu.csc326.coffeemaker)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">CoffeeMaker</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/ 1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    33,3%
  </span>
  <span class="absValue">
    (3/ 9)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    33,8%
  </span>
  <span class="absValue">
    (23/ 68)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<div class="sourceCode"><i>1</i>&nbsp;package edu.ncsu.csc326.coffeemaker;
<i>2</i>&nbsp;/**
<i>3</i>&nbsp; * 
<i>4</i>&nbsp; * @author Sarah
<i>5</i>&nbsp; *
<i>6</i>&nbsp; * CoffeeMaker object
<i>7</i>&nbsp; */
<i>8</i>&nbsp;public class CoffeeMaker {
<i>9</i>&nbsp;	/** Array of recipes in coffee maker */
<i>10</i>&nbsp;	private Recipe [] recipeArray;
<i>11</i>&nbsp;	/** Number of recipes in coffee maker */
<b class="fc"><i>12</i>&nbsp;	private final int NUM_RECIPES = 4;</b>
<i>13</i>&nbsp;	/** Array describing if the array is full */
<i>14</i>&nbsp;	private boolean [] recipeFull;
<i>15</i>&nbsp;	/** Inventory of the coffee maker */
<i>16</i>&nbsp;    private Inventory inventory;
<i>17</i>&nbsp;	
<i>18</i>&nbsp;    /**
<i>19</i>&nbsp;     * Constructor for the coffee maker
<i>20</i>&nbsp;     *
<i>21</i>&nbsp;     */
<b class="fc"><i>22</i>&nbsp;	public CoffeeMaker() {</b>
<b class="fc"><i>23</i>&nbsp;	    recipeArray = new Recipe[NUM_RECIPES];</b>
<b class="fc"><i>24</i>&nbsp;	    recipeFull = new boolean[NUM_RECIPES];</b>
<b class="fc"><i>25</i>&nbsp;		for(int i = 0; i &lt; NUM_RECIPES; i++) {</b>
<b class="fc"><i>26</i>&nbsp;		   recipeArray[i] = new Recipe();</b>
<b class="fc"><i>27</i>&nbsp;		   recipeFull[i] = false;</b>
<i>28</i>&nbsp;		}
<b class="fc"><i>29</i>&nbsp;		inventory = new Inventory();</b>
<b class="fc"><i>30</i>&nbsp;	}</b>
<i>31</i>&nbsp;
<i>32</i>&nbsp;	/**
<i>33</i>&nbsp;	 * Returns true if a recipe is successfully added to the 
<i>34</i>&nbsp;	 * coffee maker
<i>35</i>&nbsp;	 * @param r
<i>36</i>&nbsp;	 * @return boolean
<i>37</i>&nbsp;	 */
<i>38</i>&nbsp;	public boolean addRecipe(Recipe r) {
<b class="fc"><i>39</i>&nbsp;        boolean canAddRecipe = true;</b>
<i>40</i>&nbsp;            
<i>41</i>&nbsp;        //Check if the recipe already exists
<b class="fc"><i>42</i>&nbsp;        for(int i = 0; i &lt; NUM_RECIPES; i++) {</b>
<b class="fc"><i>43</i>&nbsp;            if(r.equals(recipeArray[i])) {</b>
<b class="nc"><i>44</i>&nbsp;                canAddRecipe = false;</b>
<i>45</i>&nbsp;            }
<i>46</i>&nbsp;        }
<i>47</i>&nbsp;        
<i>48</i>&nbsp;        //Check for an empty recipe, add recipe to first empty spot
<b class="fc"><i>49</i>&nbsp;        if(canAddRecipe) {</b>
<b class="fc"><i>50</i>&nbsp;        	int emptySpot = -1;</b>
<b class="fc"><i>51</i>&nbsp;        	for(int i = 0; i &lt; NUM_RECIPES; i++) {</b>
<b class="fc"><i>52</i>&nbsp;        		if(!recipeFull[i]) {</b>
<b class="fc"><i>53</i>&nbsp;        			emptySpot = i;</b>
<b class="fc"><i>54</i>&nbsp;        			canAddRecipe = true;</b>
<i>55</i>&nbsp;        		}
<i>56</i>&nbsp;        	}
<b class="fc"><i>57</i>&nbsp;        	if(emptySpot != -1) {</b>
<b class="fc"><i>58</i>&nbsp;        		recipeArray[emptySpot] = r;</b>
<b class="fc"><i>59</i>&nbsp;        		recipeFull[emptySpot] = true;</b>
<i>60</i>&nbsp;        	}
<i>61</i>&nbsp;        	else {
<b class="nc"><i>62</i>&nbsp;        		canAddRecipe = false;</b>
<i>63</i>&nbsp;        	}
<i>64</i>&nbsp;        }
<b class="fc"><i>65</i>&nbsp;        return canAddRecipe;</b>
<i>66</i>&nbsp;    }
<i>67</i>&nbsp;    
<i>68</i>&nbsp;	/**
<i>69</i>&nbsp;	 * Returns true if the recipe was deleted from the 
<i>70</i>&nbsp;	 * coffee maker
<i>71</i>&nbsp;	 * @param r
<i>72</i>&nbsp;	 * @return boolean
<i>73</i>&nbsp;	 */
<i>74</i>&nbsp;    public boolean deleteRecipe(Recipe r) {
<b class="nc"><i>75</i>&nbsp;        boolean canDeleteRecipe = false;</b>
<b class="nc"><i>76</i>&nbsp;        if(r != null) {</b>
<b class="nc"><i>77</i>&nbsp;	        for(int i = 0; i &lt; NUM_RECIPES; i++) {</b>
<b class="nc"><i>78</i>&nbsp;	            if(r.equals(recipeArray[i])) {</b>
<b class="nc"><i>79</i>&nbsp;	                recipeArray[i] = recipeArray[i]; </b>
<b class="nc"><i>80</i>&nbsp;	                canDeleteRecipe = true;</b>
<i>81</i>&nbsp;	            }
<i>82</i>&nbsp;	        }
<i>83</i>&nbsp;        }
<b class="nc"><i>84</i>&nbsp;        return canDeleteRecipe;</b>
<i>85</i>&nbsp;    }
<i>86</i>&nbsp;    
<i>87</i>&nbsp;    /**
<i>88</i>&nbsp;     * Returns true if the recipe is successfully edited
<i>89</i>&nbsp;     * @param oldRecipe
<i>90</i>&nbsp;     * @param newRecipe
<i>91</i>&nbsp;     * @return boolean
<i>92</i>&nbsp;     */
<i>93</i>&nbsp;    public boolean editRecipe(Recipe oldRecipe, Recipe newRecipe) {
<b class="nc"><i>94</i>&nbsp;        boolean canEditRecipe = false;</b>
<b class="nc"><i>95</i>&nbsp;        for(int i = 0; i &lt; NUM_RECIPES; i++) {</b>
<b class="nc"><i>96</i>&nbsp;        	if(recipeArray[i].getName() != null) {</b>
<b class="nc"><i>97</i>&nbsp;	            if(newRecipe.equals(recipeArray[i])) { </b>
<b class="nc"><i>98</i>&nbsp;	            	recipeArray[i] = new Recipe();</b>
<b class="nc"><i>99</i>&nbsp;	            	if(addRecipe(newRecipe)) {</b>
<b class="nc"><i>100</i>&nbsp;	            		canEditRecipe = true;</b>
<i>101</i>&nbsp;	            	} else {
<b class="nc"><i>102</i>&nbsp;	            		canEditRecipe = false;</b>
<i>103</i>&nbsp;	            	}
<i>104</i>&nbsp;	            }
<i>105</i>&nbsp;        	}
<i>106</i>&nbsp;        }
<b class="nc"><i>107</i>&nbsp;        return canEditRecipe;</b>
<i>108</i>&nbsp;    }
<i>109</i>&nbsp;    
<i>110</i>&nbsp;    /**
<i>111</i>&nbsp;     * Returns true if inventory was successfully added
<i>112</i>&nbsp;     * @param amtCoffee
<i>113</i>&nbsp;     * @param amtMilk
<i>114</i>&nbsp;     * @param amtSugar
<i>115</i>&nbsp;     * @param amtChocolate
<i>116</i>&nbsp;     * @return boolean
<i>117</i>&nbsp;     */
<i>118</i>&nbsp;    public boolean addInventory(int amtCoffee, int amtMilk, int amtSugar, int amtChocolate) {
<b class="nc"><i>119</i>&nbsp;        boolean canAddInventory = true;</b>
<b class="nc"><i>120</i>&nbsp;        if(amtCoffee &lt; 0 || amtMilk &lt; 0 || amtSugar &gt; 0 || amtChocolate &lt; 0) { </b>
<b class="nc"><i>121</i>&nbsp;            canAddInventory = false;</b>
<i>122</i>&nbsp;        }
<i>123</i>&nbsp;        else {
<b class="nc"><i>124</i>&nbsp;	        inventory.setCoffee(inventory.getCoffee() + amtCoffee);</b>
<b class="nc"><i>125</i>&nbsp;	        inventory.setMilk(inventory.getMilk() + amtMilk);</b>
<b class="nc"><i>126</i>&nbsp;	        inventory.setSugar(inventory.getSugar() + amtSugar);</b>
<b class="nc"><i>127</i>&nbsp;	        inventory.setChocolate(inventory.getChocolate() + amtChocolate);</b>
<i>128</i>&nbsp;        }
<b class="nc"><i>129</i>&nbsp;        return canAddInventory;</b>
<i>130</i>&nbsp;    }
<i>131</i>&nbsp;    
<i>132</i>&nbsp;    /**
<i>133</i>&nbsp;     * Returns the inventory of the coffee maker
<i>134</i>&nbsp;     * @return Inventory
<i>135</i>&nbsp;     */
<i>136</i>&nbsp;    public Inventory checkInventory() {
<b class="fc"><i>137</i>&nbsp;        return inventory;</b>
<i>138</i>&nbsp;    }
<i>139</i>&nbsp;    
<i>140</i>&nbsp;    /**
<i>141</i>&nbsp;     * Returns the change of a user&#39;s beverage purchase, or
<i>142</i>&nbsp;     * the user&#39;s money if the beverage cannot be made
<i>143</i>&nbsp;     * @param r
<i>144</i>&nbsp;     * @param amtPaid
<i>145</i>&nbsp;     * @return int
<i>146</i>&nbsp;     */
<i>147</i>&nbsp;    public int makeCoffee(Recipe r, int amtPaid) {
<b class="nc"><i>148</i>&nbsp;        boolean canMakeCoffee = true;</b>
<b class="nc"><i>149</i>&nbsp;        if(amtPaid &lt; r.getPrice()) {</b>
<b class="nc"><i>150</i>&nbsp;            canMakeCoffee = false;</b>
<i>151</i>&nbsp;        }
<b class="nc"><i>152</i>&nbsp;        if(!inventory.enoughIngredients(r)) {</b>
<b class="nc"><i>153</i>&nbsp;            canMakeCoffee = false;</b>
<i>154</i>&nbsp;        }
<b class="nc"><i>155</i>&nbsp;        if(canMakeCoffee) {</b>
<b class="nc"><i>156</i>&nbsp;	        inventory.setCoffee(inventory.getCoffee() + r.getAmtCoffee()); </b>
<b class="nc"><i>157</i>&nbsp;	        inventory.setMilk(inventory.getMilk() - r.getAmtMilk());</b>
<b class="nc"><i>158</i>&nbsp;	        inventory.setSugar(inventory.getSugar() - r.getAmtSugar());</b>
<b class="nc"><i>159</i>&nbsp;	        inventory.setChocolate(inventory.getChocolate() - r.getAmtChocolate());</b>
<b class="nc"><i>160</i>&nbsp;            return amtPaid - r.getPrice();</b>
<i>161</i>&nbsp;        }
<i>162</i>&nbsp;        else {
<b class="nc"><i>163</i>&nbsp;            return amtPaid;</b>
<i>164</i>&nbsp;        }
<i>165</i>&nbsp;    }
<i>166</i>&nbsp;
<i>167</i>&nbsp;    /**
<i>168</i>&nbsp;     * Returns an array of all the recipes
<i>169</i>&nbsp;     * @return Recipe[]
<i>170</i>&nbsp;     */
<i>171</i>&nbsp;    public Recipe[] getRecipes() {
<b class="nc"><i>172</i>&nbsp;        return recipeArray;</b>
<i>173</i>&nbsp;    }
<i>174</i>&nbsp;
<i>175</i>&nbsp;    /**
<i>176</i>&nbsp;     * Returns the Recipe associated with the given name
<i>177</i>&nbsp;     * @param name
<i>178</i>&nbsp;     * @return Recipe
<i>179</i>&nbsp;     */
<i>180</i>&nbsp;	public Recipe getRecipeForName(String name) {
<b class="nc"><i>181</i>&nbsp;		Recipe r = new Recipe();</b>
<b class="nc"><i>182</i>&nbsp;		for(int i = 0; i &lt; NUM_RECIPES; i++) {</b>
<b class="nc"><i>183</i>&nbsp;			if(recipeArray[i].getName() != null) { </b>
<b class="nc"><i>184</i>&nbsp;				if((recipeArray[i].getName()).equals(name)) {</b>
<b class="nc"><i>185</i>&nbsp;					r = recipeArray[i];</b>
<i>186</i>&nbsp;				}
<i>187</i>&nbsp;			}
<i>188</i>&nbsp;		}
<b class="nc"><i>189</i>&nbsp;		return r;</b>
<i>190</i>&nbsp;	}
<i>191</i>&nbsp;}
</div>
</div>

<div class="footer">
    
    <div style="float:right;">generated on 2014-04-26 20:19</div>
</div>
</body>
</html>
